using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Shuriken.Core.UI.StandardUI
{
    public partial class TextItemView : UserControl
    {
        private bool m_ControlSelected;
        // private string m_TextContent;

        public TextItemView()
        {
            InitializeComponent();
            m_ControlSelected = false;
            txtText.Text = string.Empty;  

            ControlSelectedChanged(m_ControlSelected);
        }

        /// <summary>
        /// Content this control is holding 
        /// </summary>
        public string TextContet
        {
            get { return txtText.Text; }
            set { TextContentChanged(value); }
        }

        private void TextContentChanged(string content)
        {
            this.txtText.Text = content;
        }

        /// <summary>
        /// Gets or Sets if the control is selected or not. 
        /// </summary>
        public bool ControlSelected
        {
            get { return m_ControlSelected; }
            set 
            { 
                m_ControlSelected = value;
                ControlSelectedChanged(m_ControlSelected);
            }
        }

        /// <summary>
        /// Handles the changes between the selected and non-selected states. 
        /// </summary>
        /// <param name="m_ControlSelected">control selection state</param>
        private void ControlSelectedChanged(bool m_ControlSelected)
        {
            if (m_ControlSelected)
            {
                // Selected
                detailsPanel.GradientHighColor = System.Drawing.Color.Linen;
                detailsPanel.GradientLowColor = System.Drawing.Color.Orange;
                detailsPanel.BorderColor = new Ascend.BorderColor(Color.Orange);

                this.lblText.Visible = false; 

                this.txtText.Enabled = true; 
                this.txtText.Visible = true;
                this.txtText.SelectAll();
                this.txtText.Focus();
            }
            else
            {
                this.txtText.Enabled = false;
                this.txtText.Visible = false;
                this.lblText.Visible = true; 

                // UnSelected 
                this.lblText.Text = txtText.Text; 
                detailsPanel.GradientHighColor = System.Drawing.Color.White;
                detailsPanel.GradientLowColor = System.Drawing.Color.LightSteelBlue;
                detailsPanel.BorderColor = new Ascend.BorderColor(Color.Gray);
                //detailsPanel.BorderColor = new Ascend.BorderColor(Color.LightSteelBlue);

            }
        }

        /// <summary>
        /// Back key pressed, going to send a message to the text edit field. 
        /// </summary>
        internal void HandleBackKeyPressed()
        {
            // Send the Key.Back message to the text edit control 
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
